package rexsee.fingerdrawing;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;
import android.app.Activity;
import android.content.Context;

public class RexseeFingerDrawing implements JavascriptInterface {

	public static final String INTERFACE_NAME = "FingerDrawing";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeFingerDrawing(childBrowser);
	}

	public final Context mContext;
	private final Browser mBrowser;

	public RexseeFingerDrawing(Browser browser) {
		mContext = browser.getContext();
		mBrowser = browser;
		browser.eventList.add(FingerDrawingDialog.EVENT_ONFINGERDRAWINGREADY);
	}

	//JavaScript Interface
	public void open(final String style) {
		((Activity) mContext).runOnUiThread(new Runnable() {
			@Override
			public void run() {
				new FingerDrawingDialog(mBrowser, style).start();
			}
		});
	}
}
